package com.geodroid.action;

import java.util.ArrayList;

import android.graphics.RectF;
import android.util.Log;
import android.view.MotionEvent;

import com.geodroid.common.kernel.geos.GeoPoint2;
import com.geodroid.euclidian.Drawable;
import com.geodroid.euclidian.EuclidianView;

public class ActionCreatePoint extends Action {
	private String TAG = "ActionCreatePoint" ; 
	@Override
	public boolean validate(Drawable d) {
		return true;
	}

	/**
	 * @param nbClicked
	 * @param draSel
	 */
	public ActionCreatePoint(int nbClicked, ArrayList<Drawable> draSel) {
		super(nbClicked, draSel);
	}
	
	/**
	 * @param view 
	 * 
	 */
	public ActionCreatePoint() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param isStarted
	 * @param nbClicked
	 * @param draSel
	 */
	public ActionCreatePoint(boolean isStarted, int nbClicked,ArrayList<Drawable> draSel) {
		super(isStarted, nbClicked, draSel);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void dealWith(MotionEvent event,EuclidianView view) {
		//we create the drawable ...
		int action = event.getAction();
		float x = event.getX();
		float y = event.getY();
		float width = event.getTouchMajor();
		float height = event.getTouchMinor();
		RectF touchedArea = new RectF(x-width/2,y-height/2,x+width/2,y+height/2) ;
		switch (action) {
			case MotionEvent.ACTION_DOWN:
				process(touchedArea,view) ;
			default:
		}
		
		
	}

	/* (non-Javadoc)
	 * @see com.geodroid.action.Action#process(int, float, float, java.util.ArrayList)
	 */
	@Override
	public void process(RectF touchedArea, EuclidianView view) {
		// TODO Auto-generated method stub

		Log.d(TAG,"<process>") ; 
		double rwX = view.toRealWorldCoordX(touchedArea.centerX()) ; 
		double rwY = view.toRealWorldCoordY(touchedArea.centerY()) ;
		view.addPoint(new GeoPoint2(rwX,rwY)) ; 
		Log.d(TAG,"</process>") ; 

	}

	/* (non-Javadoc)
	 * @see com.geodroid.action.Action#processDown(android.graphics.RectF, com.geodroid.euclidian.EuclidianView)
	 */
	@Override
	protected void processDown(RectF touchedArea, EuclidianView view) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see com.geodroid.action.Action#processMove(android.graphics.RectF, com.geodroid.euclidian.EuclidianView)
	 */
	@Override
	protected void processMove(RectF touchedArea, EuclidianView view) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see com.geodroid.action.Action#processUp(android.graphics.RectF, com.geodroid.euclidian.EuclidianView)
	 */
	@Override
	protected void processUp(RectF touchedArea, EuclidianView view) {
		// TODO Auto-generated method stub
		
	}

	

	
	


}
